import com.wmm.LinkList;

public class Work2 {

    public static void main(String[] args) {

        LinkList n1=new LinkList(1,"张飞");
        LinkList n2=new LinkList(2,"关羽");
        LinkList n3=new LinkList(3,"赵云");
        LinkList n4=new LinkList(4,"黄忠");
        LinkList n5=new LinkList(5,"马超");
        n1.next=n2;
        n2.next=n3;
        n3.next=n4;
        n4.next=n5;
        n5.next=n1;
        System.out.println(isRing(n1));

    }


    public static boolean isRing(LinkList head){
        if(head == null) return false;
        LinkList slow = head; //慢指针
        LinkList fast = head.next;  //快指针

        while (fast !=null && fast.next != null){
            if (slow == fast){
                return true;
            }
            slow = slow.next; //慢指针每次走一步
            fast = fast.next.next; //快指针每次走2步
        }

        return false;
    }
}
